package at.fhooe.swa.client.ui;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.Map.Entry;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import at.fhooe.swa.client.domain.ISensorHistoryData;

public class HistoryFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	
//	private JPanel dataPanel = null;
	
	ISensorHistoryData sensorHistoryData = null;
	
	public HistoryFrame(ISensorHistoryData sensorData)
	{
		this.sensorHistoryData = sensorData;
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setPreferredSize(new Dimension(400, 400));
		
		init();
	}
	
	private void init()
	{

		this.setLayout(new BorderLayout());
		
		// Table Column Labels
		String[] columnNames = {"Date/Time", "Value"};
		// Table data
		Object[][] data = new Object[this.sensorHistoryData.getHistoryData().size()][2];
		
//		System.out.println(sensorHistoryData.getHistoryData().size());
		
		int i = 0;
		// fill data into the data array
		for (Entry<String, Object> entry : this.sensorHistoryData.getHistoryData().entrySet())
		{
			data[i][0] = entry.getKey();
			data[i][1] = entry.getValue();
			i++;
		}
//		System.out.println(data.length);
		
		// create the table
		JTable table = new JTable(data, columnNames);
		// add scroll pane
		JScrollPane scrollPane = new JScrollPane(table);
		table.setFillsViewportHeight(true);
		
		this.add(scrollPane, BorderLayout.CENTER);
	}

}
